package ucadminlogic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"navi-mumbai/app/rpc/model/pg/usercenter"
	"navi-mumbai/app/rpc/usercenter/internal/svc"
	"navi-mumbai/app/rpc/usercenter/pb"
	"navi-mumbai/common/utils"
	"navi-mumbai/common/xerr"
)

type UpdateServiceUpdateConfigLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateServiceUpdateConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateServiceUpdateConfigLogic {
	return &UpdateServiceUpdateConfigLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 创建ServiceUpdateConfig设置
func (l *UpdateServiceUpdateConfigLogic) UpdateServiceUpdateConfig(in *pb.UpdateServiceUpdateConfigReq) (*pb.UpdateServiceUpdateConfigResp, error) {
	defer utils.RecoverPanic()

	uf := usercenter.ServiceUpdateConfig{
		Id:      in.Id,
		Version: in.Version,
		Enable:  in.Enable,
	}

	err := l.svcCtx.UserServiceUpdateConfigModel.Update(l.ctx, &uf)
	if err != nil {
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}
	return &pb.UpdateServiceUpdateConfigResp{}, nil
}
